<template>
  <el-backtop :bottom="60"></el-backtop>
  <el-container class="home-container">
    <el-header>
      <el-aside width="200px">
        <el-row type="flex" justify="center"> 数据管理面板</el-row>
      </el-aside>
      <el-col :span="19">
        <div class="toggle-button" @click="toggleCollapase">
          <el-icon size="20px">
            <Fold/>
          </el-icon>
        </div>
      </el-col>
      <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" circle
                 @click="infoVisible = true"/>
      <hr/>
      <el-button type="danger" :icon="Close" circle @click="dialogVisible = true"/>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <el-menu background-color="#0f0303" text-color="#fff" active-text-color="#409eff" unique-opened
                 :collapse="isCollapse" :collapse-transition="false" :router="true" :default-active="$route.path">
          <el-menu-item index="/Info" key="0">
            <el-icon>
              <List/>
            </el-icon>
            <template #title>信息总览</template>
          </el-menu-item>

          <el-sub-menu index="/management" key="1">
            <template #title>
              <el-icon>
                <Cloudy/>
              </el-icon>
              <span>数据管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/college">
                <el-icon>
                  <House/>
                </el-icon>
                学院
              </el-menu-item>
              <el-menu-item index="/major">
                <el-icon>
                  <Management/>
                </el-icon>
                专业
              </el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item index="/class">
                <el-icon>
                  <Monitor/>
                </el-icon>
                班级
              </el-menu-item>
              <el-menu-item index="/student">
                <el-icon>
                  <Avatar/>
                </el-icon>
                学生
              </el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item index="/question">
                <el-icon>
                  <Document/>
                </el-icon>
                题目
              </el-menu-item>
              <el-menu-item index="/result">
                <el-icon>
                  <Filter/>
                </el-icon>
                结果
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-menu-item index="/visual" key="2">
            <el-icon>
              <DataAnalysis/>
            </el-icon>
            <template #title>数据可视化</template>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

  <el-dialog title="退出" v-model="dialogVisible" width="30%" draggable>
    <el-descriptions title="">
      <el-descriptions-item label="">
        <span>
          亲爱的管理员 {{ username }}，感谢您的使用，欢迎您再次登录 M B T I
          综合数据管理平台</span>
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="danger" @click="logout">退出登录</el-button>
        <el-button @click="dialogVisible = false">返回</el-button>
      </span>
    </template>
  </el-dialog>

  <el-dialog title="账号信息" v-model="infoVisible" width="20%" draggable>
    <el-row type="flex" justify="center">
      <el-avatar :size="120" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png">
      </el-avatar>
    </el-row>
    <br/>
    <el-row type="flex" justify="center">
      <el-descriptions title="">
        <el-descriptions-item label="身份">
          <el-tag size="small">管理员</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </el-row>
    <el-row type="flex" justify="center">
      <el-descriptions title="">
        <el-descriptions-item label="账号">
          <el-tag size="small">{{ username }}</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </el-row>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="infoVisible = false">返回</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { Close } from "@element-plus/icons-vue";
import store from "@/store";

export default {
  data() {
    return {
      isCollapse: false,
      dialogVisible: false,
      infoVisible: false,
      username: store.getters.name,
      Close,
    };
  },
  methods: {
    async logout() {
      await this.$store.dispatch('user/logout');
      this.$message.success("退出成功");
      this.$router.push('/login');
    },

    toggleCollapase() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>

<style scoped>
.el-header {
  background-color: #0f0303;
  display: flex;
  padding-left: 0%;
  align-items: center;
  color: #fff;
  font-size: 20px;
}

.el-aside {
  background-color: #0f0303;
}

.el-main {
  background-color: #eaedf1;
}

.home-container {
  height: 100%;
}

.home-container .el-avatar {
  cursor: pointer;
}

.toggle-button {
  background-color: #0f0303;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: left;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
